// 下包，导包
import Vue from "vue";
import VueRouter from "vue-router";

// 在vue中使用组件:<router-view></router-view>，<router-link></router-link>
Vue.use(VueRouter);

// 按需引入页面组件
const Home = () => import("@/views/Home.vue");
const Index = () => import("@/views/Index.vue");
const newList = () => import("@/views/NewList/newList.vue");
const newDetail = () => import("@/views/NewList/newDetail.vue");
const article = () => import("@/views/article/articleList.vue");
const articleDetail = () => import("@/views/article/articleDetail.vue");
const produceList = () => import("@/views/Produce/produceList.vue");
const produceDetail = () => import("@/views/Produce/produceDetail.vue");
const introduction = () => import("@/views/Produce/introduction.vue");
const produceComment = () => import("@/views/Produce/produceComment.vue");
const shoppingCar = () => import("@/views/shoppingCar.vue/index.vue");
// 创建路由规则数据
const routes = [
  // 重定向
  { path: "/", redirect: "/home" },
  {
    path: "/home",
    component: Home,
    redirect: "/home/index",
    children: [
      { path: "index", component: Index },
      { path: "newList", component: newList },
      { path: "newDetail/:id", component: newDetail },
      { path: "article", component: article },
      { path: "articleDetail/:id", component: articleDetail },
      { path: "produceList", component: produceList },
      { path: "produceDetail/:id", component: produceDetail },
      { path: "introduction/:id", component: introduction },
      { path: "produceComment/:id", component: produceComment },
      { path: "shoppingCar/:id", component: shoppingCar },
    ],
  },
];

// 创建路由实例
const router = new VueRouter({
  routes: routes,
  //  hash模式修改，去除路径的/#
  mode: "history",
});

// 导出路由
export default router;
